package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-07-23
 * Time: 17:48
 */
public class Demo10 {
    public static void main(String[] args) {
        Thread b = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("b end");
        });
        Thread a = new Thread(() -> {
            for (int i = 0; i < 3; i++) {
                System.out.println("a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                b.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("a end");
        });

        a.start();
        b.start();
    }
}
